<template>
  <div>
      id:<input type="text" v-model="id"><br>
      名字:<input type="text" v-model="name"><br>
      销量:<input type="text" v-model="sale"><br>
      价格:<input type="text" v-model="price"><br>
      所属作者:<select v-model="type_id">
          <option :value="data.id" v-for="data in datas">{{data.name}}</option>
      </select><br>
      <button @click="add">添加</button>
  </div>
</template>

<script>
export default {
    name:'book_post',
    data(){
        return{
            datas:[],
            id:'',
            name:'',
            sale:'',
            price:'',
            type_id:''
        }
    },
    methods:{
        getdata(){
            this.axios.get('yt1/').then(res=>{
                this.datas=res.data
            })
        },
        add(){
            let data= new FormData();
            data.append('id',this.id)
            data.append('name',this.name)
            data.append('sale',this.sale)
            data.append('price',this.price)
            data.append('type_id',this.type_id)
            this.axios.post('yt4/',data).then(res=>{
                this.$router.push('book_get')
            })
        }
    },
    mounted(){
        this.getdata()
    }

}
</script>

<style>

</style>